import { createRouter, createWebHistory } from 'vue-router'
import layout from '@/views/layout/index.vue'
import login from '@/views/login/index.vue'
import home from '@/views/home/index.vue'
import category from '@/views/category/index.vue'
import SubCategory from '@/views/SubCategory.vue'
import detail from '@/views/detail/index.vue'
import CartList from '@/views/CartList.vue'
import CheckOut from '@/views/CheckOut.vue'
import PayOrder from '@/views/PayOrder.vue'
import PayBack from '@/views/PayBack.vue'
import Member from '@/views/member/index.vue'
import UserInfo from '@/views/member/components/UserInfo.vue'
import UserOrder from '@/views/member/components/UserOrder.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: layout,
      // 配置二级路由组件
      children: [
        {
          path: '',
          name: 'home',
          component: home,
        },
        // 商品一级分类
        {
          path: '/category/:id',
          name: 'category',
          component: category,
        },
        // 商品二级分类
        {
          path: '/category/sub/:id',
          name: 'SubCategory',
          component: SubCategory,
        },
        // 商品详情页
        {
          path: '/detail/:id',
          name: 'detail',
          component: detail
        },
        // 购物车列表
        {
          path: '/cartlist',
          name: 'CartList',
          component: CartList
        },
        // 结算页
        {
          path: '/checkout',
          name: 'CheckOut',
          component: CheckOut
        },
        // 支付页
        {
          path: '/pay',
          name: 'PayOrder',
          component: PayOrder
        },
        // 支付结果页
        {
          path: '/paycallback',
          component: PayBack
        },
        {
          path: '/member',
          component: Member,
          children: [
            {
              path: '',
              component: UserInfo
            },
            {
              path: 'order',
              component: UserOrder
            },
          ]
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: login
    },

  ],
  // 路由滚动行为
  scrollBehavior () {
    return {
      top:0
    }
  }
})

export default router
